package com.itheima.yichang;

import java.util.Scanner;

/**
 * @author zhangbaiyan
 * @date 2024-09-18 13:31
 * @description:1
 * @version: 1
 */
public class test2 {

    public static void main(String[] args) {

//        1.创建键盘录入对象
        Scanner sc = new Scanner(System.in);
        //船舰女朋友对象
        Girlfriend gf = new Girlfriend();
        while (true) {
            try {
                System.out.println("请输入你心仪的女盆友名字");
                String name = sc.nextLine();
                gf.setName(name);
                //接收女盆友的年龄
                System.out.println("请输入你心仪的女盆友年龄");
                String age = sc.nextLine();
                gf.setAge(Integer.parseInt(age));
                //如果所有数据正确的话跳出循环
                break;
            } catch (NumberFormatException e) {
                e.printStackTrace();
            } catch (NameFormatException e) {
                e.printStackTrace();
            }catch (AgeOutOfBoundsException e) {
                e.printStackTrace();
            }
        }

        System.out.println("你心仪的女盆友是："+gf.getName()+"今年"+gf.getAge()+"岁");


    }
}
